﻿using System.Diagnostics.CodeAnalysis;
using DimensionsHelper.LanguageService.Protocol;
using DimensionsHelper.LanguageService.Resources;
using DimensionsHelper.Serialization.Constants;

namespace DimensionsHelper.LanguageService;

/// <summary>
///     内置的错误信息
/// </summary>
/// <param name="Severity">错误严重性</param>
/// <param name="Code">错误编码</param>
/// <param name="MessageFormat">错误信息模板</param>
public record DiagnosticDescriptor(
    [ConstantTargetMatcher(@"Error|Warning|Information|Hint(?=_\d+_\w+)")]
    DiagnosticSeverity Severity,
    [ConstantTargetMatcher(@"(?<=(Error|Warning|Information|Hint)_)\d+(?=_\w+)")]
    int Code,
    [ConstantValue] string MessageFormat);


[ConstantsClass(typeof(ErrorMessages), typeof(string), typeof(DiagnosticDescriptor), Validator = FieldNamePattern,
    NameMatcher = FieldNameMatchPattern)]
internal static partial class DiagnosticDescriptors
{
    [StringSyntax("Regex")]
    private const string FieldNamePattern = @"(?<type>Error|Warning|Information|Hint)_(?<code>\d+)_(?<name>\w+)";

    [StringSyntax("Regex")]
    private const string FieldNameMatchPattern = @"(?<=(Error|Warning|Information|Hint)_\d+_)\w+";
}